package MapandSetHomeWork;

import java.util.Map;
import java.util.TreeMap;

public class TreeMapTraverse {
    public static void main(String[] args) {
        //使用Map.entrySet进行遍历
        TreeMap<Integer,String> treeMap = new TreeMap<>();
        treeMap.put(1,"djm");
        treeMap.put(2,"zzx");
        treeMap.put(3,"zjy");

        System.out.println("打印键值对:");
        for (Map.Entry<Integer, String> entry : treeMap.entrySet()) {
            System.out.println("key:"+entry.getKey() + " value:"+entry.getValue());
        }

        System.out.println("******************");
        System.out.println("打印键:");
        //使用Map.keySet遍历
        for (Integer i : treeMap.keySet()) {
            System.out.println(i);
        }

        //使用Map.values进行遍历
        System.out.println("******************");
        System.out.println("打印值:");
        for (String value : treeMap.values()) {
            System.out.println(value);
        }
    }
}
